package com.lineage.server.model.skill.skillmode;

import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1CastleLocation;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Magic;
import com.lineage.server.model.L1Object;
import com.lineage.server.serverpackets.S_Message_YN;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.World;
import java.util.Iterator;

public class GREATER_RESURRECTION extends SkillMode {
  public int start(L1PcInstance srcpc, L1Character cha, L1Magic magic, int integer) throws Exception {
    int dmg = 0;
    if (cha instanceof L1PcInstance) {
      L1PcInstance pc = (L1PcInstance)cha;
      boolean castle_area1 = L1CastleLocation.checkInAllWarArea(cha.getX(), cha.getY(), cha.getMapId());
      if (castle_area1)
        return 0; 
      boolean castle_area2 = L1CastleLocation.checkInAllWarArea(pc.getX(), pc.getY(), pc.getMapId());
      if (castle_area2)
        return 0; 
      if (srcpc.getId() != pc.getId()) {
        if (World.get().getVisiblePlayer((L1Object)pc, 0).size() > 0) {
          Iterator<L1PcInstance> iterator = World.get().getVisiblePlayer((L1Object)pc, 0).iterator();
          while (iterator.hasNext()) {
            L1PcInstance visiblePc = iterator.next();
            if (!visiblePc.isDead()) {
              srcpc.sendPackets((ServerBasePacket)new S_ServerMessage(592));
              return 0;
            } 
          } 
        } 
        if (pc.isDead() && pc.getMap().isUseResurrection()) {
          pc.setGres(true);
          pc.setTempID(srcpc.getId());
          pc.sendPackets((ServerBasePacket)new S_Message_YN(322));
        } 
      } 
    } 
    if (cha instanceof L1NpcInstance && !(cha instanceof com.lineage.server.model.Instance.L1TowerInstance)) {
      L1NpcInstance npc = (L1NpcInstance)cha;
      if (npc.getNpcTemplate().isCantResurrect())
        return 0; 
      if (npc instanceof com.lineage.server.model.Instance.L1PetInstance && World.get().getVisiblePlayer((L1Object)npc, 0).size() > 0) {
        Iterator<L1PcInstance> iterator2 = World.get().getVisiblePlayer((L1Object)npc, 0).iterator();
        while (iterator2.hasNext()) {
          L1PcInstance visiblePc2 = iterator2.next();
          if (!visiblePc2.isDead()) {
            srcpc.sendPackets((ServerBasePacket)new S_ServerMessage(592));
            return 0;
          } 
        } 
      } 
      if (npc.isDead()) {
        npc.resurrect(npc.getMaxHp() / 4);
        npc.setResurrect(true);
      } 
    } 
    return 0;
  }
  
  public int start(L1NpcInstance npc, L1Character cha, L1Magic magic, int integer) throws Exception {
    int dmg = 0;
    return 0;
  }
  
  public void start(L1PcInstance srcpc, Object obj) throws Exception {}
  
  public void stop(L1Character cha) throws Exception {}
}
